﻿
(function (window, undefined) {

    var $ = window.$, app = {};

    app.settings = {
        serivceUrl: "",
        appid: "appidTest",
        currentUser: "F459DEF9-6D6B-E611-9F24-4CCC6A479139"//结合appkey加密过的
    };

    app.ajax = function (setting) {
        if (setting.url.indexOf('api/') > -1) {
            setting.url = window.app.settings.serivceUrl + setting.url;
        }
        if (!setting.headers) {
            setting.headers = {
                appid: window.app.settings.appid,
                currentUser: window.app.settings.currentUser
            };
        } 

        //if (!setting.beforeSend) {
        //    setting.beforeSend = function (xhr) {
        //        //xhr.setRequestHeader("appId", "appTest");
        //    }
        //}
        return jQuery.ajax(setting);
    }
    app.get = function (url, data, callback, type) {
        return app.ajax({
            url: url,
            type: "GET",
            dataType: type,
            data: data,
            success: callback
        });
    };
    app.getJSON = function (url, data, callback) {
        return app.get(url, data, callback, "json");
    }


    if (!window.app) window.app = app;

}(window));